package com.yzc.android.network.request;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.yzc.android.network.base.KDGsonRequest;
import com.yzc.android.network.base.KDRequestQueue;
import com.yzc.android.network.base.VolleyManager;
import com.yzc.android.network.mock.GsonMapResponse;
import com.yzc.android.network.response.SectionDataListResponse;
import com.yzc.android.network.response.SectionDataResponse;
import com.yzc.android.network.response.SectionInfoResponse;

/**
 * Created by yzc on 16/5/5.
 */
public class FakeRequestFactory {

    public static KDGsonRequest<SectionDataListResponse> getMockData(final Response.Listener<SectionDataListResponse> successListener,
                                                                     final Response.ErrorListener errorListener)
    {
        KDRequestQueue queue = VolleyManager.getRequestQueue();
        Map<String, String> params = new HashMap<>();
        params.put("method", "c.my.infoview");

        KDGsonRequest<SectionDataListResponse> request = new KDGsonRequest<>(Method.GET, SectionDataListResponse.class, params,
                                                                             new Listener<SectionDataListResponse>() {
                                                                                 @Override
                                                                                 public void onResponse(final SectionDataListResponse response) {
                                                                                     if (successListener != null)
                                                                                     {
                                                                                         successListener.onResponse(response);
                                                                                     }

                                                                                 }
                                                                             }, new ErrorListener() {
            @Override
            public void onErrorResponse(final VolleyError error) {
                if (errorListener != null)
                {
                    errorListener.onErrorResponse(error);
                }
            }
        });

        List<SectionDataResponse> dataList = new ArrayList<>();
        SectionDataResponse dataBean1 = new SectionDataResponse();
        dataBean1.mId = "1";
        dataBean1.mContent = "Load more Demo";
        dataBean1.mType = SectionDataResponse.kDataTypeLoadMore;
        SectionInfoResponse section1 = new SectionInfoResponse();
        section1.sectionId = 1;
        section1.sectionTitle = "Basic";
        section1.sectionImgUrl = null;
        dataBean1.mSectionBean = section1;
        dataList.add(dataBean1);

        SectionDataResponse dataBean2 = new SectionDataResponse();
        dataBean2.mId = "2";
        dataBean2.mContent = "Multi view Demo";
        dataBean2.mType = SectionDataResponse.kDataTypeMulti;
        SectionInfoResponse section2 = new SectionInfoResponse();
        section2.sectionId = 2;
        section2.sectionTitle = "Advance";
        section2.sectionImgUrl = null;
        dataBean2.mSectionBean = section2;
        dataList.add(dataBean2);


        SectionDataResponse dataBean3 = new SectionDataResponse();
        dataBean3.mId = "3";
        dataBean3.mContent = "Scroll Demo";
        dataBean3.mType = SectionDataResponse.kDataTypeScroll;
        SectionInfoResponse section3 = new SectionInfoResponse();
        section3.sectionId = 2;
        section3.sectionTitle = "Advance";
        section3.sectionImgUrl = null;
        dataBean3.mSectionBean = section3;
        dataList.add(dataBean3);

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("code", 200);
        paramMap.put("data", dataList);
        request.setFakeResponse(new GsonMapResponse(paramMap, 200));
        queue.add(request, errorListener);
        return request;
    }
}
